<?php echo $javascript->link('filter_actions'); ?>
<div class="anotations index">
    <a href="" class="filtro_a" onclick="show_filter(); return false;"><?php echo __('Filtro', true); ?></a>
    <input type="hidden" id="input_filtro" value="0">
    <div id="filtro_busqueda" class="filtro" style="display: block">
        <fieldset>
            <?php echo $form->create('Anotation', array('url' => array('controller' => 'anotations', 'action' => 'index'))); ?>
            <div class="date_range">
                <label>Rango de Fechas</label>
                <?php
                echo $form->input('date_from', array('label' => false));
                ?>
                <span>-</span>
                <?php
                echo $form->input('date_to', array('label' => false));
                ?>
                <span><?php echo $this->Html->link(__('Hoy', true), array(), array('onclick' => 'fecha_hoy(); return false;')); ?></span>
                &nbsp;&nbsp;&nbsp;
                <span><?php echo $this->Html->link(__('Próximos 7 Días', true), array(), array('onclick' => 'fecha_semana(); return false;')); ?></span>
                <?php
                echo $form->input('hidden_actual_date', array('type' => 'hidden', 'value' => date('d/m/Y')));
                echo $form->input('hidden_week_date', array('type' => 'hidden', 'value' => date('d/m/Y', strtotime('+7 day', strtotime(date('Y-m-d H:i:s'))))));
                ?> 
            </div>
            <?php echo $form->input('description', array('label' => 'Descripción', 'type' => 'text')); ?>
            <?php
            echo $form->submit(__('Filtrar', true));
            echo $form->end();
            ?>
        </fieldset>
    </div>
    <h2 class="left"><?php __('Anotaciones'); ?></h2>
    <div class="actions specific right">
        <ul>
            <li><?php echo $this->Html->link(__('Agregar Nuevo', true), array('action' => 'add')); ?> </li>
        </ul>
    </div>
    <table cellpadding="0" cellspacing="0">
        <tr>
            <th><?php echo $this->Paginator->sort('Fecha de Inicio', 'start_date'); ?></th>
            <th><?php echo $this->Paginator->sort('Descripción', 'description'); ?></th>
            <th class="actions"><?php __('Acciones'); ?></th>
        </tr>
        <?php
        if (count($anotations) == 0) {
            ?> 
            <tr>
                <td colspan="3">No se encontraron Anotaciones</td>
            </tr>
            <?php
        }

        $i = 0;
        foreach ($anotations as $anotation):
            $class = null;
            if ($i++ % 2 == 0) {
                $class = ' class="altrow"';
            }
            ?>
            <tr<?php echo $class; ?>>
                <td><?php
        echo date('d/m/Y', strtotime($anotation['Anotation']['start_date']));
        echo '<br />';
        echo date('H:i', strtotime($anotation['Anotation']['start_date'])) . ' - ' . date('H:i', strtotime($anotation['Anotation']['finish_date']));
            ?>&nbsp;</td>
                <td><?php echo $anotation['Anotation']['description']; ?>&nbsp;</td>
                <td class="actions">
                    <?php echo $this->Html->link($this->Html->image('icons/magnifier.png'), array('action' => 'view', $anotation['Anotation']['id']), array('title' => __('Ver', true), 'escape' => false)); ?>
                    <?php echo $this->Html->link($this->Html->image('icons/pencil.png'), array('action' => 'edit', $anotation['Anotation']['id']), array('title' => __('Editar', true), 'escape' => false)); ?>
                    <?php echo $this->Html->link($this->Html->image('icons/cross.png'), array('action' => 'delete', $anotation['Anotation']['id']), array('title' => __('Eliminar', true), 'escape' => false), sprintf(__('Seguro que desea eliminar esta Anotación?', true), $anotation['Anotation']['id'])); ?>
                </td>
            </tr>
        <?php endforeach; ?>
    </table>
    <p>
        <?php
        echo $this->Paginator->counter(array(
            'format' => __('Página %page% de %pages%, mostrando %current% registros de %count% en total, a partir del registro %start%, terminando en el %end%', true)
        ));
        ?>	</p>

    <div class="paging">
        <?php echo $this->Paginator->prev('<< ' . __('Anterior', true), array(), null, array('class' => 'disabled')); ?>
        | 	<?php echo $this->Paginator->numbers(); ?>
        |
        <?php echo $this->Paginator->next(__('Siguiente', true) . ' >>', array(), null, array('class' => 'disabled')); ?>
    </div>
</div>
<script type="text/javascript" >

    (function($){
        // Date picker
        $("#AnotationDateFrom").datepicker({
            //yearRange: '1970:2010',
            defaultDate: new Date(),
            dateFormat: 'dd/mm/yy',
            changeMonth: true,
            changeYear: true
        });
        // Date picker
        $("#AnotationDateTo").datepicker({
            //yearRange: '1970:2010',
            defaultDate: new Date(),
            dateFormat: 'dd/mm/yy',
            changeMonth: true,
            changeYear: true
        });

    })(jQuery);
    
    function fecha_hoy(){
        var hoy = $('#AnotationHiddenActualDate').val();
        $('#AnotationDateFrom').val(hoy);
        $('#AnotationDateTo').val(hoy);
        $('#AnotationIndexForm').submit();
    }
    
    function fecha_semana(){
        var hoy = $('#AnotationHiddenActualDate').val();
        var semana = $('#AnotationHiddenWeekDate').val();
        $('#AnotationDateFrom').val(hoy);
        $('#AnotationDateTo').val(semana);
        $('#AnotationIndexForm').submit();
    }
</script>